<script setup lang="ts">
import { computed, Ref, ref } from 'vue';
import { HotType } from '@/service/api/type/goods.type'
import { findHotGoods } from '@/service/api/goods'
import { IGoods } from '@/service/api/type/category.type';
import CategoryItem from '@/view/category/components/category-item.vue';
const props = withDefaults(defineProps<{
  type?: HotType,
  goodsId: string
}>(), {
  type: 0
})

const titleMap = { 0: '24小时热销榜', 1: '周热销榜', 2: '总热销榜' }
const title = computed(() => titleMap[props.type])

const hotGoodsList: Ref<IGoods[]> = ref([])

const getHotGoodsData = async () => {
  const response = await findHotGoods(props.goodsId, props.type)
  hotGoodsList.value.push(...response.result)
}

getHotGoodsData()

</script>

<template>
  <div class="goods-hot">
    <h3>{{ title }}</h3>
    <div v-if="hotGoodsList.length">
      <CategoryItem v-for="item in hotGoodsList" :key="item.id" :good="item" />
    </div>
  </div>
</template>

<style lang="less" scoped>
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
  :deep(.goods-item) {
    background: #fff;
    width: 100%;
    margin-bottom: 10px;
    img {
      width: 200px;
      height: 200px;
    }
    p {
      margin: 0 10px;
    }
    &:hover {
      transform: none;
      box-shadow: none;
    }
  }
}
</style>
